import httpx
import re
import pymysql
import time
import json
import requests
import pandas

conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                       database='sunway_db', charset='utf8')
cursor = conn.cursor()


def mysql1(company_name, track_status, trackNumber, label_name, stayTimeLength, itemTimeLength, Dates,
           StatusDescription_Details, update_date, create_time, all_):
    newtime = time.strftime('%Y-%m-%d %H:%M:%S')
    # 重复数据重复读存
    order_id = str(all_[0])
    platform = str(all_[1])
    Reference_number = str(all_[2])
    Sales_Order_No = str(all_[3])
    Warehouse_delivery_time = str(all_[4])
    Account_alias = str(all_[5])
    Warehouse_name = str(all_[6])
    Warehouse_code = str(all_[7])
    Warehouse_SKU = str(all_[8])
    Platform_SKU = str(all_[9])
    Order_site = str(all_[10])
    Recipient_country_two_character_code = str(all_[11])
    Country_name = str(all_[12])
    Warehouse_transportation_mode_code = str(all_[13])
    Name_of_warehouse_transportation_mode = str(all_[14])
    Service_provider_name = str(all_[15])
    Tracking_number = str(all_[16])
    cursor.execute(
        "REPLACE into Small_package_Logistics_51 set newtime=%s,company_name=%s,track_status=%s,trackNumber=%s,label_name=%s,stayTimeLength=%s,itemTimeLength=%s,Dates=%s,StatusDescription_Details=%s,update_date=%s,create_time=%s,order_id=%s,platform=%s,Reference_number=%s,Sales_Order_No=%s,Warehouse_delivery_time=%s,Account_alias=%s,Warehouse_name=%s,Warehouse_code=%s,Warehouse_SKU=%s,Platform_SKU=%s,Order_site=%s,Recipient_country_two_character_code=%s,Country_name=%s,Warehouse_transportation_mode_code=%s,Name_of_warehouse_transportation_mode=%s,Service_provider_name=%s,Tracking_number=%s",
        [newtime, company_name, track_status, trackNumber, label_name, stayTimeLength, itemTimeLength, Dates,
         StatusDescription_Details, update_date, create_time, order_id, platform, Reference_number, Sales_Order_No,
         Warehouse_delivery_time, Account_alias, Warehouse_name, Warehouse_code, Warehouse_SKU, Platform_SKU,
         Order_site, Recipient_country_two_character_code, Country_name, Warehouse_transportation_mode_code,
         Name_of_warehouse_transportation_mode, Service_provider_name,Tracking_number])

    conn.commit()


def mysql2(e, f, z0_time, z0_title, z1_time, z1_title, i, all_):
    newtime = time.strftime('%Y-%m-%d %H:%M:%S')
    # 重复数据重复读存
    order_id = str(all_[0])
    platform = str(all_[1])
    Reference_number = str(all_[2])
    Sales_Order_No = str(all_[3])
    Warehouse_delivery_time = str(all_[4])
    Account_alias = str(all_[5])
    Warehouse_name = str(all_[6])
    Warehouse_code = str(all_[7])
    Warehouse_SKU = str(all_[8])
    Platform_SKU = str(all_[9])
    Order_site = str(all_[10])
    Recipient_country_two_character_code = str(all_[11])
    Country_name = str(all_[12])
    Warehouse_transportation_mode_code = str(all_[13])
    Name_of_warehouse_transportation_mode = str(all_[14])
    Service_provider_name = str(all_[15])

    cursor.execute(
        "REPLACE into Small_package_Logistics_17 set newtime=%s,e=%s,f=%s,z0_time=%s,z0_title=%s,z1_time=%s,z1_title=%s,Tracking_number=%s,order_id=%s,platform=%s,Reference_number=%s,Sales_Order_No=%s,Warehouse_delivery_time=%s,Account_alias=%s,Warehouse_name=%s,Warehouse_code=%s,Warehouse_SKU=%s,Platform_SKU=%s,Order_site=%s,Recipient_country_two_character_code=%s,Country_name=%s,Warehouse_transportation_mode_code=%s,Name_of_warehouse_transportation_mode=%s,Service_provider_name=%s",
        [newtime, e, f, z0_time, z0_title, z1_time, z1_title, i, order_id, platform, Reference_number, Sales_Order_No,
         Warehouse_delivery_time, Account_alias, Warehouse_name, Warehouse_code, Warehouse_SKU, Platform_SKU,
         Order_site, Recipient_country_two_character_code, Country_name, Warehouse_transportation_mode_code,
         Name_of_warehouse_transportation_mode, Service_provider_name])

    conn.commit()


def func(i, all_):
    headers = {
        'Accept': '*/*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'Connection': 'keep-alive',
        'Cookie': '{}'.format(func1()),
        'Host': 'my.51tracking.com',
        'Referer': 'https://my.51tracking.com/numbers.php?lang=cn&e=279891479@qq.com&v=paid&keywordType=trackNumber&p=1&searchnumber={}'.format(
            i),
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest',
    }

    parma = {
        'lang': 'cn',
        'action': 'get_my_number',
        'source': '2',
        'where': 'lang=cn&e=279891479@qq.com&v=paid&keywordType=trackNumber&p=1&searchnumber={}'.format(i),
        'page': '1',
    }

    url = 'https://my.51tracking.com/data/data-numbers.php?lang=cn&action=get_my_number&source=2&where=lang=cn&e=279891479@qq.com&v=paid&keywordType=trackNumber&p=1&searchnumber={}'.format(
        i)
    # print(url)
    # try:
    #     result = httpx_(i,all_)
    # except Exception as g:
    result = httpx_(i,all_)
    if result == 'Success':#向51物流网站推送数据
        # print('0000000000000000000000')
        if httpx.get(url=url, headers=headers, params=parma).status_code == 200:
            # try:
                response = httpx.get(url=url, headers=headers, params=parma,timeout=10).json()
                if response['code'] == 200:
                    # print(response)
                    dicts = {
                        '0': '查询中',
                        '1': '查询不到',
                        '2': '运输途中',
                        '4': '成功签收',
                        '5': '运输过久',
                        '6': '投递失败',
                        '7': '可能异常',
                        '8': '待上网',
                        '3': '到达待取'
                    }

                    company_name = response['data'][0]['company_name']  # 物流名称
                    track_status = dicts['{}'.format(response['data'][0]['track_status'])]  # 物流运输状态
                    trackNumber = response['data'][0]['trackNumber']  # 物流快递单号
                    label_name = response['data'][0]['label_name']  # 姓名
                    stayTimeLength = response['data'][0]['stayTimeLength']  # 停留时间
                    itemTimeLength = response['data'][0]['itemTimeLength']  # 运输时间
                    update_date = response['data'][0]['update_date']  # 更新时间
                    create_time = response['data'][0]['create_time']  # 添加时间
                    # data_list = []
                    if track_status == '查询不到':
                        Dates = '0000-00-00 00:00:00'
                        StatusDescription_Details = ''
                        print('51网站',company_name, track_status, trackNumber, label_name, stayTimeLength, itemTimeLength, Dates,
                              StatusDescription_Details, update_date, create_time)
                        mysql1(company_name, track_status, trackNumber, label_name, stayTimeLength, itemTimeLength, Dates,
                               StatusDescription_Details, update_date, create_time, all_)
                    else:
                        for data in response['data'][0]['cacheInfo']['gyd']['trackinfo']:
                            Dates = data['Date']
                            data1 = data['StatusDescription']
                            data2 = data['Details']
                            StatusDescription_Details = data1 + data2

                            print('51网站',company_name, track_status, trackNumber, label_name, stayTimeLength, itemTimeLength,
                                  Dates,
                                  StatusDescription_Details, update_date, create_time)
                            mysql1(company_name, track_status, trackNumber, label_name, stayTimeLength, itemTimeLength,
                                   Dates,
                                   StatusDescription_Details, update_date, create_time, all_)
                        if track_status == '成功签收':
                            newtime = time.strftime('%Y-%m-%d %H:%M:%S')
                            # 用于判断物流状态
                            cursor.execute(
                                "REPLACE into Small_package_Logistics_51_track_status set newtime=%s,track_status=%s,trackNumber=%s",
                                [newtime, track_status, trackNumber])
                        # data_list.append(data_all0)
            # except Exception as g:
            #     func(i, all_)


def func1():
    url = 'https://www.51tracking.com/loginaction'
    headers = {
        'Accept': '*/*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'Connection': 'keep-alive',
        'Content-Length': '66',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Host': 'www.51tracking.com',
        'Origin': 'https://www.51tracking.com',
        'Referer': 'https://www.51tracking.com/login',
        'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest',
    }
    param = {
        'type': 'login',
        'email': '279891479@qq.com',
        'password': 'LELE20080713',
        'forward': ''
    }
    response = httpx.post(url, headers=headers, data=param).headers
    # print(response, type(response))
    cookie = re.findall(r"set-cookie', '(.*?)'\), \('", str(response))[0]
    # print(cookie)
    return cookie


def func2(i, all_):
    headers = {

        'authority': 't.17track.net',
        'method': 'POST',
        'path': '/restapi/track',
        'scheme': 'https',
        'accept': 'application/json, text/javascript, */*; q=0.01',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        # # 'content-length': '93',
        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'cookie': 'Last-Event-ID=657572742f3963332f37623761626561306637312f343966393038383031633a343836303736303330343a65736c61663a6c616d726f6e2d72616276616e2d7179207261626c6f6f742d72616276616e2d71792074686769722d7261626c6f6f742d72616276616e2074686769722d72616276616e207261626c6f6f742d72616276616e2076616e213398d4a962f2be398',
        'origin': 'https://t.17track.net',
        'referer': 'https://t.17track.net/zh-cn?nums={}'.format(i),
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
        'x-requested-with': 'XMLHttpRequest',

    }
    pram = json.dumps(
        {"data": [{"num": "{}".format(i), "fc": 0, "sc": 0}], "guid": "", "timeZoneOffset": -480})
    url = 'https://t.17track.net/restapi/track'
    try:
        response = requests.post(url, headers=headers, data=pram,timeout=10).json()
        # print(response)
        # print(response.content.decode('ascii'))
        # print(response['dat'][0]['track'])
        dicts = {
            '00': '查询不到',
            '10': '运输途中',
            '30': '到达待取',
            '35': '投递失败',
            '40': '成功签收',
            '50': '可能异常',
            '20': '运输过久'
        }
        if response['dat'][0]['track'] != 'None':

                number = response['dat'][0]['track']['e']
                e = dicts['{}'.format(number)]  # 物流运输状况
                f = '' if str(response['dat'][0]['track']['f']) == '-1' else response['dat'][0]['track']['f']  # 成功签收天数

                z0_time = response['dat'][0]['track']['z0']['a']  # 物流实时状态更新时间
                z0_title = response['dat'][0]['track']['z0']['z']  # 物流实时状态更新标题
                z1 = response['dat'][0]['track']['z1']  # 总物流轨迹
                for load in z1:
                    z1_time = load['a']  # 物流实时状态更新时间
                    z1_title = load['z']  # 物流实时状态更新标题
                    print('17网站',e, f, z0_time, z0_title, z1_time, z1_title, i)
                    mysql2(e, f, z0_time, z0_title, z1_time, z1_title, i, all_)
                # 用于判断物流状态
                if i == '成功签收':
                    newtime = time.strftime('%Y-%m-%d %H:%M:%S')
                    cursor.execute(
                        "REPLACE into Small_package_Logistics_17_track_status set newtime=%s,e=%s,i=%s",
                        [newtime, e, i])

        else:
            func2(i, all_)
    except TypeError as f:
        print('################################################################')


def field():
    newtime = time.strftime('%Y-%m-%d')
    conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                           database='sunway_db', charset='utf8')
    # cursor = conn.cursor()
    # Service_provider_1 = ['鄂宝物流', '卓志速运', '睿捷物流', '派敏斯物流V2', '云途物流-顺才']  # 51代码所需服务商综合
    # Service_provider_2 = ['欧速通物流服务']#17代码所需服务商综合
    Channel_code_1 = ['4PXEXPRESS_O5_AM', 'YUNWAY_THPHR_YT_SC', 'CNE_CNE3033', 'WC_PMS_PMSUKYYB', 'WB_UKSLR',
                      'UBI_UBICN2WW_GENERAL_YW', 'UBI_UBICN2WW_GENERAL', 'WC_ZTGJ_ZPAU', 'WC_ZTGJ_ZPAU_NSW',
                      'WC_ZTGJ_ZPAU_WA', 'WC_ZTGJ_ZPAU_OTHER', 'WC_ZTGJ_AU', 'ZZSY_TAUSZZFCNT_XB', 'ZZSY_TAUSZZFCNT',
                      'ZZSY_TAUSZZFCET', 'ZZSY_TAUSZZFCET_XB', 'WC_PMS_PMSUS004NYB_MDDB', 'WC_PMS_PMSUS004NYB_MDXB',
                      'WC_PMS_PMSUS004NYB_MXXB', 'WC_PMS_PMSUS004NYB_MXDB', 'EBOFP', 'YUNWAY_THPHR_WC_SC',
                      'YUNWAY_BKPHR_SC', 'YUNWAY_BKZXR_SC', 'YUNWAY_THZXR_WC_SC', 'YUNWAY_THZXR_YT_SC',
                      'YUNWAY_BKPHR_YT_SC', 'WC_RJ_RJUSZSMXDB', 'WC_RJ_RJUSZSMXXB', 'WC_RJ_RJUSZSXB',
                      'WC_RJ_RJUSZSDB']  # 渠道代码
    Channel_code_2 = ['CNE_CNE2500', 'WC_PMS_PMSUKTYB', 'WC_PMS_PMSDEHYB', 'LTGJ_CAXNC_MG', 'SPEX_MPAK-UK-TRACKED']
    resquests_mysql_17_ = resquests_mysql_17()  # 调用成功签收sku
    resquests_mysql_51_ = resquests_mysql_51()  # 调用成功签收sku
    datas = "select order_id,platform,Reference_number,Sales_Order_No,Warehouse_delivery_time,Account_alias,Warehouse_name,Warehouse_code,Warehouse_SKU,Platform_SKU,Order_site,Recipient_country_two_character_code,Country_name,Tracking_number,Warehouse_transportation_mode_code,Name_of_warehouse_transportation_mode,Service_provider_name from Small_package_Logistics_all"
    a = pandas.read_sql(datas, conn)
    # print(a['name'])
    list_guolv = []
    for i in range(0,len(a['Service_provider_name'])):
        if a['Tracking_number'][i] not in list_guolv:  # 过滤重复的sku
            list_guolv.append(a['Tracking_number'][i])
            order_id = a['order_id'][i]
            platform = a['platform'][i]
            Reference_number = a['Reference_number'][i]
            Sales_Order_No = a['Sales_Order_No'][i]
            Warehouse_delivery_time = a['Warehouse_delivery_time'][i]
            Account_alias = a['Account_alias'][i]
            Warehouse_name = a['Warehouse_name'][i]
            Warehouse_code = a['Warehouse_code'][i]
            Warehouse_SKU = a['Warehouse_SKU'][i]
            Platform_SKU = a['Platform_SKU'][i]
            Order_site = a['Order_site'][i]
            # Recipient_country_two_character_code = a['Recipient_country_two_character_code'][i]
            Country_name = a['Country_name'][i]
            Warehouse_transportation_mode_code = a['Warehouse_transportation_mode_code'][i]
            Recipient_country_two_character_code = a['Recipient_country_two_character_code'][i]
            Name_of_warehouse_transportation_mode = a['Name_of_warehouse_transportation_mode'][i]
            Service_provider_name = a['Service_provider_name'][i]
            Tracking_number = a['Tracking_number'][i]
            all_ = [order_id, platform, Reference_number, Sales_Order_No, Warehouse_delivery_time, Account_alias,
                    Warehouse_name, Warehouse_code, Warehouse_SKU, Platform_SKU, Order_site,
                    Recipient_country_two_character_code, Country_name, Warehouse_transportation_mode_code,
                    Name_of_warehouse_transportation_mode, Service_provider_name,Tracking_number]
            # print(i, a['Warehouse_transportation_mode_code'][i], '*', a['Tracking_number'][i])
            # and str(a['Warehouse_delivery_time'][i]) == '1900-01-20'
            if a['Warehouse_transportation_mode_code'][i] in Channel_code_1 and a['Warehouse_name'][i] in ['佛山仓',
                                                                                                           '义乌仓'] and \
                    a['Tracking_number'][i] != '' and a['Tracking_number'][i] not in resquests_mysql_51_:
                func(a['Tracking_number'][i], all_)
                # print('guo')
                # and str(a['Warehouse_delivery_time'][i]) == '1900-01-20'
            elif a['Warehouse_transportation_mode_code'][i] in Channel_code_2 and a['Warehouse_name'][i] in ['佛山仓',
                                                                                                             '义乌仓'] and \
                    a['Tracking_number'][i] != '' and a['Tracking_number'][i] not in resquests_mysql_17_:

                func2(a['Tracking_number'][i], all_)
            else:
                continue
                # print(a['Tracking_number'][i],a['Warehouse_transportation_mode_code'][i])


def resquests_mysql_17():  # 获取成功签收sku
    conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                           database='sunway_db', charset='utf8')
    datas = "select i from Small_package_Logistics_17_track_status"
    a = pandas.read_sql(datas, conn)
    return a['i']


def resquests_mysql_51():  # 获取成功签收sku
    conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                           database='sunway_db', charset='utf8')
    datas = "select trackNumber from Small_package_Logistics_51_track_status"
    a = pandas.read_sql(datas, conn)
    return a['trackNumber']


def httpx_(i,all_):  # 跟踪号提交请求至物流平台获取物流轨迹



    country_usa = {
        "CNE_CNE3033": "hermes-uk",
        "WC_PMS_PMSUKYYB": "yodel",
        "WB_UKSLR": "yodel",
        "UBI_UBICN2WW_GENERAL_YW": "ubi-logistics",
        "UBI_UBICN2WW_GENERAL": "ubi-logistics",
        "WC_ZTGJ_ZPAU": "australia-post",
        "WC_ZTGJ_ZPAU_NSW": "australia-post",
        "WC_ZTGJ_ZPAU_WA": "australia-post",
        "WC_ZTGJ_ZPAU_OTHER": "australia-post",
        "WC_ZTGJ_AU": "fastway-au",
        "ZZSY_TAUSZZFCNT_XB": "usps",
        "ZZSY_TAUSZZFCET_XB": "usps",
        "ZZSY_TAUSZZFCNT": "usps",
        "ZZSY_TAUSZZFCET": "usps",
        "WC_PMS_PMSUS004NYB_MDDB": "usps",
        "WC_PMS_PMSUS004NYB_MDXB": "usps",
        "WC_PMS_PMSUS004NYB_MXXB": "usps",
        "WC_PMS_PMSUS004NYB_MXDB": "usps",
        "WC_RJ_RJUSZSMXDB": "usps",
        "WC_RJ_RJUSZSMXXB": "usps",
        "WC_RJ_RJUSZSXB": "usps",
        "WC_RJ_RJUSZSDB": "usps",
        "EBO-EBOFP": "usps",
        "WB_DEEXR": "dhl-germany",
        "CNE_CNE_DE": "dhl-germany",
        "EDIS_ES": "orangeconnex",
        "EDIS_ES-YW": "orangeconnex",
        "EDIS1_ES-YW": "orangeconnex",
        "EDIS_EE": "orangeconnex",
        "EDIS_ES_DD": "orangeconnex",
        "EDIS1_ES_DD": "orangeconnex",
        "EDIS1_ES": "orangeconnex",
        "EDIS2_ES": "orangeconnex",
        "EDIS2_ES_YW": "orangeconnex",
        "EDIS_EE-YW": "orangeconnex",
        "WC_RJ_RJGBYSL": "yodel",
        "YUNWAY_THZXR_WC_SC": "usps",
        "YUNWAY_THPHR_WC_SC": "usps",
        "YUNWAY_BKZXR_SC": "usps",
        "YUNWAY_BKPHR_YT_SC": "yunexpress",
        "YUNWAY_BKPHR_SC": "usps",
        "YUNWAY_THPHR_YT_SC": "yunexpress",
        "YUNWAY_THZXR_YT_SC": "yunexpress",
    }

    country_unusa = {
        "CNE_CNE3033": "hermes-uk",
        "WC_PMS_PMSUKYYB": "yodel",
        "WB_UKSLR": "yodel",
        "UBI_UBICN2WW_GENERAL_YW": "ubi-logistics",
        "UBI_UBICN2WW_GENERAL": "ubi-logistics",
        "WC_ZTGJ_ZPAU": "australia-post",
        "WC_ZTGJ_ZPAU_NSW": "australia-post",
        "WC_ZTGJ_ZPAU_WA": "australia-post",
        "WC_ZTGJ_ZPAU_OTHER":"australia-post",
        "WC_ZTGJ_AU": "fastway-au",
        "ZZSY_TAUSZZFCNT_XB": "usps",
        "ZZSY_TAUSZZFCET_XB": "usps",
        "ZZSY_TAUSZZFCNT": "usps",
        "ZZSY_TAUSZZFCET": "usps",
        "WC_PMS_PMSUS004NYB_MDDB": "usps",
        "WC_PMS_PMSUS004NYB_MDXB": "usps",
        "WC_PMS_PMSUS004NYB_MXXB": "usps",
        "WC_PMS_PMSUS004NYB_MXDB": "usps",
        "WC_RJ_RJUSZSMXDB": "usps",
        "WC_RJ_RJUSZSMXXB": "usps",
        "WC_RJ_RJUSZSXB": "usps",
        "WC_RJ_RJUSZSDB": "usps",
        "EBO-EBOFP": "usps",
        "WB_DEEXR": "dhl-germany",
        "CNE_CNE_DE": "dhl-germany",
        "EDIS_ES": "orangeconnex",
        "EDIS_ES-YW": "orangeconnex",
        "EDIS1_ES-YW": "orangeconnex",
        "EDIS_EE": "orangeconnex",
        "EDIS_ES_DD": "orangeconnex",
        "EDIS1_ES_DD": "orangeconnex",
        "EDIS1_ES": "orangeconnex",
        "EDIS2_ES": "orangeconnex",
        "EDIS2_ES_YW": "orangeconnex",
        "EDIS_EE-YW": "orangeconnex",
        "WC_RJ_RJGBYSL": "yodel",
        "YUNWAY_THZXR_WC_SC": "yunexpress",
        "YUNWAY_THPHR_WC_SC": "yunexpress",
        "YUNWAY_BKZXR_SC": "yunexpress",
        "YUNWAY_BKPHR_YT_SC": "yunexpress",
        "YUNWAY_BKPHR_SC": "yunexpress",
        "YUNWAY_THPHR_YT_SC": "yunexpress",
        "YUNWAY_THZXR_YT_SC": "yunexpress",
    }

    country_gr = {
        "4PXEXPRESS_O5_AM": "dhl-germany"
    }
    country_gb = {
        "4PXEXPRESS_O5_AM": "4PX"
    }

    Recipient_country_two_character_code = str(all_[11])
    Warehouse_transportation_mode_code = str(all_[13])
    country_one = None
    if Recipient_country_two_character_code == 'US':
        country_one = country_usa[Warehouse_transportation_mode_code]
    elif Recipient_country_two_character_code == 'GB' and Warehouse_transportation_mode_code =='4PXEXPRESS_O5_AM':
        country_one = country_gb[Warehouse_transportation_mode_code]
    elif Recipient_country_two_character_code == 'DE' and Warehouse_transportation_mode_code =='4PXEXPRESS_O5_AM':
        country_one = country_gr[Warehouse_transportation_mode_code]
    else:
        country_one = country_unusa[Warehouse_transportation_mode_code]


    headers = {
        'Accept': '*/*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'Connection': 'keep-alive',
        # 'Content-Length': '142',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Cookie': '{}'.format(func1()),
        'Host': 'my.51tracking.com',
        'Origin': 'https://my.51tracking.com',
        'Referer': 'https://my.51tracking.com/tools/newParcelNew.php?lang=cn&formId=0',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest',
    }

    data = {
        'type': 'add-single-number',
        'number': '{}'.format(i),
        'express': '{}'.format(country_one),
        'special': 'none',
        'order_id': '',
        'order_create_time': '',
        'comment': '',
        'phone': '',
        'email': '',
        'lang': 'cn',
    }
    res = httpx.post(headers=headers, url='https://my.51tracking.com/data/data-api.php', data=data,timeout=10).json()
    print(res)
    return res['message']





if __name__ == '__main__':
    field()
    # func1()
